package com.lottery.material.service.admin.message.impl;

import com.lottery.material.dao.message.SystemMessageInfoMapper;
import com.lottery.material.pojo.message.SystemMessageInfo;
import com.lottery.material.pojo.page.Page;
import com.lottery.material.pojocustom.message.SystemMessageInfoCustom;
import com.lottery.material.service.admin.message.SystemMessageInfoService;
import com.lottery.material.util.CalendarUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Description：系统消息信息服务接口实现类
 * Created by 朱正磊 on 2019-04-13 17:25
 */
@Service("adminSystemMessageInfoService")
public class SystemMessageInfoServiceImpl implements SystemMessageInfoService {

    private final SystemMessageInfoMapper systemMessageInfoMapper;

    @Autowired
    public SystemMessageInfoServiceImpl(SystemMessageInfoMapper systemMessageInfoMapper) {
        this.systemMessageInfoMapper = systemMessageInfoMapper;
    }

    /**
     * description：新增一条数据
     * user 朱正磊
     * time 2019-04-20 15:14
     * @param systemMessageInfo 对象
     * @return 返回持久化操作数据库状态值
     */
    @Override
    public Integer add(SystemMessageInfo systemMessageInfo) {
        systemMessageInfo.setCreateTime(new Date());
        return systemMessageInfoMapper.insertSelective(systemMessageInfo);
    }

    /**
     * description：根据主键物理删除
     * user 朱正磊
     * time 2019-04-20 15:13
     * @param id 主键
     * @return 返回持久化操作数据库状态值
     */
    @Override
    public Integer deleteById(Integer id) {
        return systemMessageInfoMapper.deleteByPrimaryKey(id);
    }

    /**
     * description：根据主键查询唯一数据
     * user 朱正磊
     * time 2019-04-20 15:15
     * @param id 主键
     * @return 返回唯一数据
     */
    @Override
    public SystemMessageInfo findById(Integer id) {
        return systemMessageInfoMapper.selectByPrimaryKey(id);
    }

    /**
     * description：根据主键修改一条数据
     * user 朱正磊
     * time 2019-04-20 15:16
     * @param systemMessageInfo 对象
     * @return 返回持久化操作数据库状态值
     */
    @Override
    public Integer updateById(SystemMessageInfo systemMessageInfo) {
        return systemMessageInfoMapper.updateByPrimaryKeySelective(systemMessageInfo);
    }

    /**
     * description：查询扩展类分页列表
     * user 朱正磊
     * time 2019-04-17 17:01
     * @param page 分页对象
     * @return 返回扩展类分页列表数据
     */
    @Override
    public List<SystemMessageInfoCustom> findCustomListPage(Page page) {
        List<SystemMessageInfoCustom> list = systemMessageInfoMapper.findCustomListPage(page);
        list.forEach(this::setCustom);
        return list;
    }

    /**
     * description：根据主键查询唯一扩展类数据
     * user 朱正磊
     * time 2019-04-17 17:03
     * @param id 主键
     * @return 返回唯一扩展类数据
     */
    @Override
    public SystemMessageInfoCustom findCustomById(Integer id) {
        SystemMessageInfoCustom custom = systemMessageInfoMapper.findCustomById(id);
        this.setCustom(custom);
        return custom;
    }

    /**
     * description：设置扩展类的扩展属性
     * user 朱正磊
     * time 2019-04-17 17:48
     * @param custom 扩展类对象
     */
    private void setCustom(SystemMessageInfoCustom custom) {
        //创建时间
        custom.setCreateTimeFormat(CalendarUtil.dateToString(custom.getCreateTime()));
    }
    
}
